package lan.core.io

import java.io._

trait TransferOperation {
  
  def isDone: Boolean
  def source: InputStream
  def target: OutputStream
  
  def transfer(buffer: Array[Byte]): TransferOperation = {
    val r = source.read(buffer)
    if(r < 0) {
      NoOp
    } else {
      target.write(buffer, 0, r)
      this
    }
  }
}

object NoOp extends TransferOperation {
  def isDone = true
  def source = error("NoOp does not have source")
  def target = error("NoOp does not have target")
}

class Transfer(val source: InputStream, val target: OutputStream) extends TransferOperation  {
  def isDone = false
}